/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.brainstretch.service;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import org.brainstretch.ejb.managers.QuizManager;
import org.brainstretch.ejb.managers.UserSessionManager;
import org.brainstretch.models.User;
import org.brainstretch.models.UserQuiz;
import org.brainstretch.models.actions.UserActionSummary;

/**
 *
 * @author mrodaitis
 */
@Stateless
@Path("stats")
public class UserDataService {
    
    @EJB
    QuizManager quizManager;
    
    @EJB
    UserSessionManager userManager;
    
    @GET
    @Produces({"application/json", "application/xml"})
    @Path("user")
    public Response getUserQuizData(@QueryParam("user") String username){
        User user = userManager.findUserByName(username);
        Response response = null;
        if(user != null){
            List<UserQuiz> quizzes = quizManager.getQuizzesForUser(user);            
            response =  Response.ok().entity(new UserActionSummary(quizzes)).build();
        }
        else{
            response = Response.status(Response.Status.NOT_FOUND).build();
        }
        return response;
    }
    
}
